package com.naml.k_properties;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/25 20:24
 * @desc
 */
@SuppressWarnings("all")
public class Properties01 {
    public static void main(String[] args) {
        String path = "/Users/marin/IdeaProjects/MarinJavaSe/IOStreamProject/src/db.properties";
        Properties prop = new Properties();
        try {
            //加载
            prop.load(new FileInputStream(path));
            //读取指定key
            System.out.println(prop.getProperty("username"));
            //显示全部信息
            prop.list(System.out);
            //给文件添加一些属性
            prop.setProperty("lastname", "张涛洪");
            prop.store(new FileOutputStream(path),"注释");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
